<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>图书管理</title>
    <meta name="decorator" content="default"/>
    <script src="${ctxStatic}/lodop/LodopFuncs.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function() {
            if ("${message}" != "" && "${message}" != "null") {
                showTip("${message}");
            }
        });

        function checkBanid(){
            var storeId = $("#storeId").val();
            var banId = $("#banId").val();
            $.post("${ctx}/book/store/checkRepeatBanIdById", {storeId: storeId, banId: banId}, function (result) {
                if (result) {
                    var warning = "<label for='banid' class='error'>条形码重复</label>";
                    $("#banId").after(warning);
                } else {
                    loading('正在提交，请稍等...');
                    $("#bkStoreForm").submit();
                }
            });
        }

        function getBanCode(obj) {
            var ban = $(obj).siblings("input");
            if ($(obj).is(':checked')) {
                $.post("${ctx}/book/store/createBan", null, function (result) {
                    ban.val(result);
                });
                ban.attr("readonly", "true");
            } else {
                ban.val("");
                ban.removeAttr("readonly");
            }
        }

        function bookStatus(count, banid, status) {
            $.ajax({
                type: "POST",
                url: "${ctx}/book/store/status",
                data: {banid: banid, status: status},
                dataType: "json",
                success: function (data) {
                    var status_div = $("#status_" + count);
                    showTip(data.msg, 'info');
                    if (status == 0) {
                        status_div.css({color: "red"});
                        status_div.html("作废");
                        $("#qiyong_" + count).show();
                        $("#zuofei_" + count).hide();
                    } else {
                        status_div.css({color: "green"});
                        status_div.html("正常");
                        $("#qiyong_" + count).hide();
                        $("#zuofei_" + count).show();
                    }
                }
            });
        }
        function EnterPress(obj, e) { //传入 event
            var e = e || window.event;
            if (e.keyCode == 13) {
                searchBook($(obj));
            }
        }
        function searchBook(obj) {
            var isbn = obj.val();
            $.ajax({
                type: "POST",
                url: "${ctx}/book/manage/getByIsbn",
                data: {isbn: isbn},
                dataType: "json",
                success: function (data) {
                    if (data.length >= 2) {
                        top.$.jBox.open("iframe:${ctx}/book/manage/selectBook?isbn=" + isbn, "选择图书", 800, 280, {
                            buttons: {"确定": "ok", "关闭": true}, submit: function (v, h, f) {
                                if (v == "ok") {
                                    var bkId = h.find("iframe")[0].contentWindow.getBookId();
                                    for (var i = 0; i < data.length; i++) {
                                        var result = data[i];
                                        if (result.id == bkId) {
                                            $("#bkId").val(bkId);
                                            $("#searchForm").submit();
                                            return;
                                        }
                                    }
                                }
                            }, loaded: function (h) {
                                $(".jbox-content", top.document).css("overflow-y", "hidden");
                            }
                        });
                    } else {
                        $("#bkId").val(data[0].id);
                        $("#searchForm").submit();
                    }
                }
            });
        }

        // 检查索书号
        function checkPlace() {
            var place = $("#place").val();
            parent.$.jBox.open("iframe:${ctx}/book/purchase/checkPlace?classcode=" + place, "索书号检查", 800, 600, {
                buttons: {} ,closed: function() {
                    $("#place").val(window.parent.place);
                }
            });
        }
        // 检查索书号
        function batchChangePlace() {
            var place = $("#place").val();
            place = place.split("v")[0];
            place = place.split("(")[0];
            place = place.split(":")[0];
            parent.$.jBox.open("iframe:${ctx}/book/store/goBatchChangePlace?classcode=" + place, "批量修改索书号", 800, 600, {
                buttons: {} ,closed: function() {
                }
            });
        }
    </script>
    <style>
        .form-horizontal .control-label { width: 70px; } .form-horizontal .controls { margin-left: 80px; overflow-x: hidden; } .half { width: 48%; float: left; } .thri { width: 30%; float: left; } .all { width: 90%; float: left; } .store_info { margin-left: 20%; width: 800px; margin-top: 10px; }
    </style>
</head>
    <ul class="nav nav-tabs">
        <li>
            <a href="${ctx}/book/store/list">典藏列表</a>
        </li>
        <li class="active">
            <c:if test="${isNew}">
                <a href="${ctx}/book/store/form?isEdit=true&isNew=true">
                    图书典藏（新增）
                </a>
            </c:if>
            <c:if test="${!isNew}">
                <c:if test="${isEdit}">
                    <a href="${ctx}/book/store/form?bkId=${bkBookinfo.id}&id=${bookstore.id}&isEdit=true&isNew=false">
                        图书典藏（修改）
                    </a>
                </c:if>
                <c:if test="${!isEdit}">
                    <a href="${ctx}/book/store/form?bkId=${bkBookinfo.id}&id=${bookstore.id}&isEdit=false&isNew=false">
                        图书典藏（查看）
                    </a>
                </c:if>
            </c:if>
        </li>
    </ul>
    <br/>
    <div style="width: 18%;height: 300px; float: left;padding:1%;margin-top: 30px;">
        <c:if test="${empty bkBookinfo.tubiao}">
            <img src="${ctxStatic}/images/book-default-small.gif" width="80%">
        </c:if>
        <c:if test="${not empty bkBookinfo.tubiao}">
            <img src="${bkBookinfo.tubiao}">
        </c:if>
    </div>
    <div style="width: 79%;padding-top: 5px;padding-left: 5px;float: left;font-size: 16px;">
        <fieldset>
            <legend>图书信息</legend>
            <table style="width: 95%;" class="table table-striped table-bordered table-condensed">
                <tr>
                    <th width="120">ISBN</th>
                    <td>
                        <c:if test="${isNew}">
                            <div style="margin: 0;width: 400px;float: left;">
                                <input id="isbn" name="isbn" value="${bkBookinfo.isbn}"
                                       onkeypress="EnterPress(this,event)">
                                <a class="btn btn-primary" style="width:100px;margin-left: 1%;"
                                   href="javascript:searchBook($('#isbn'))">查询</a>
                            </div>
                            <div style="float: right;width: 200px;">
                                <input id="isBooks" type="checkbox" ${bkBookinfo.books ne ''?'checked':''}>套装书
                            </div>
                        </c:if>
                        <c:if test="${!isNew}">
                            ${bkBookinfo.isbn}
                        </c:if>
                    </td>
                </tr>
                <tr>
                    <th>版次标识</th>
                    <td><span>版次标识：${bkBookinfo.edition}</span></td>
                </tr>
                <tr>
                    <th>语种</th>
                    <td>${bkBookinfo.lagclass}</td>
                </tr>
                <tr>
                    <th>题名</th>
                    <td>
                        <span>${bkBookinfo.bookname}</span><c:if
                            test="${not empty bkBookinfo.othername}"> -<span>${bkBookinfo.othername}</span></c:if>
                        <span>${bkBookinfo.pinyin}</span>
                        <span>/<a href="${ctx}/book/store/?repage&author=${bkBookinfo.author}">${bkBookinfo.author}</a></span>
                    </td>
                </tr>
                <tr>
                    <th>内容简介</th>
                    <td>${bkBookinfo.remarks}</td>
                </tr>
                <tr>
                    <th>中图分类</th>
                    <td>
                        <span>${bkBookinfo.classcode}</span>
                        <c:if test="${not empty bkBookinfo.version}">
                            <span>版次：${bkBookinfo.version}</span>
                        </c:if>
                    </td>
                </tr>
                <tr>
                    <th>主题</th>
                    <td>
                        <span>${bkBookinfo.theme}</span>
                    </td>
                </tr>
                <tr>
                    <th>出版发行</th>
                    <td>
                        <span>出版地 ：${bkBookinfo.pubplace}</span>
                <span>出版社：<a
                        href="${ctx}/book/store/?repage&publisher=${bkBookinfo.publisher}">${bkBookinfo.publisher}</a></span>
                        <span>出版时间：${bkBookinfo.pubdate}</span>
                    </td>
                </tr>
                <tr>
                    <th>载体形态</th>
                    <td>
                        <span>${bkBookinfo.pages}</span>
                        <span>${bkBookinfo.measure}</span>
                    </td>
                </tr>
                <tr>
                    <th>附件</th>
                    <td>
                        ${bkBookinfo.appendix}
                    </td>
                </tr>
                <tr>
                    <th>价格</th>
                    <td>${bkBookinfo.price}</td>
                </tr>
                <tr>
                    <th>适用对象</th>
                    <td>${bkBookinfo.endnote}</td>
                </tr>
            </table>
        </fieldset>
    </div>

    <c:if test="${!isEdit}">
    <div class="store_info">
        <fieldset>
            <legend>典藏信息</legend>
            <table style="width: 95%;" class="table table-striped table-bordered table-condensed">
                <tr>
                    <th width="120">条形码</th>
                    <td>
                            ${bookstore.banid}
                    </td>
                </tr>
                <tr>
                    <th>索取号</th>
                    <td>
                            ${bookstore.classcode}/${bookstore.place}
                    </td>
                </tr>
                <tr>
                    <th>允许外借</th>
                    <td>
                        ${bookstore.state eq '1'?'是':'否'}
                    </td>
                </tr>
                <tr>
                    <th>是否在馆</th>
                    <td>
                        ${bookstore.leftCount >= 1?'在馆':'不在馆'}
                    </td>
                </tr>
                <tr>
                    <th>批次号</th>
                    <td>${bookstore.batch}</td>
                </tr>
                <tr>
                    <th>馆藏地</th>
                    <td>${bookstore.storeName}</td>
                </tr>
                <tr>
                    <th>书架</th>
                    <td>${bookstore.shelf.name}</td>
                </tr>
            </table>
        </fieldset>
    </div>
    </c:if>


    <c:if test="${isEdit}">

        <form:form id="bkStoreForm" action="${ctx}/book/store/saveStore" method="post" class="form-horizontal store_info">
        <fieldset>
            <legend>典藏信息</legend>
            <input id="storeId" name="id" type="hidden" value="${bookstore.id}">
            <input id="bkId" name="bkId" type="hidden" value="${bookstore.bkId}">
            <table style="width: 95%;" class="table table-striped table-bordered table-condensed">
                <tr>
                    <th width="120">条形码</th>
                    <td>
                        <input id="banId" name="banid" type="text" value="${bookstore.banid}" class="required" style="width: 140px;">
                    </td>
                </tr>
                <tr>
                    <th>索取号</th>
                    <td>
                        <div class="input-append">
                            <input id="place" name="place" type="text" value="${bookstore.classcode}/${bookstore.place}"
                                   class="required" style="width: 100px;">
                            <a href="javascript:void(0)" onclick="checkPlace()" class="btn">
                                &nbsp;<i class="icon-search"></i>&nbsp;
                            </a>
                            &nbsp;&nbsp;
                            <input class="btn" style="margin-left: 10px;width:70px;" onclick="batchChangePlace()" value="批量修改"/>
                        </div>
                    </td>
                </tr>
                <tr>
                    <th>允许外借</th>
                    <td>
                        <input name="state" type="radio" value="1" ${bookstore.state eq '1'?'checked':''}>是
                        <input name="state" type="radio" value="0" ${bookstore.state ne '1'?'checked':''}>否

                    </td>
                </tr>
                <tr>
                    <th>是否在馆</th>
                    <td>
                        <input name="leftCount" type="radio" value="1" ${bookstore.leftCount >= 1?'checked':''}>是
                        <input name="leftCount" type="radio" value="0" ${bookstore.leftCount < 1?'checked':''}>否
                    </td>
                </tr>
                <tr>
                    <th>批次号</th>
                    <td>${bookstore.batch}</td>
                </tr>
                <tr>
                    <th>馆藏地</th>
                    <td>${bookstore.storeName}</td>
                </tr>
                <tr>
                    <th>书架</th>
                    <td><sys:treeselect id="shelf" name="shelf" value="${bookstore.shelf.id}" labelName="shelf.name" labelValue="${bookstore.shelf.name}"
                                        title="选择书架" url="/shelf/bkShelf/treeData" allowClear="true"/></td>
                </tr>
            </table>
            <div class="control-group all">
                <shiro:hasPermission name="book:store:save">
                    <a class="btn" style="width:80px;margin-left: 40%;"
                       href="javascript:checkBanid()">保存</a>
                </shiro:hasPermission>
                <shiro:hasPermission name="book:store:print">
                    <a class="btn" style="width:80px;margin-left: 1%;"
                       href="javascript:printTagOnCreate()">打印书标</a>
                </shiro:hasPermission>
            </div>
        </fieldset>
        </form:form>
    </c:if>


    <object id="LODOP" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0>
        <param name="Border" value="1">
        <param name="Color" value="white">
        <embed id="LODOP_EM" TYPE="application/x-print-lodop" width=0 height=0 border=0 Color="white"
               PLUGINSPAGE="install_lodop.exe">
    </object>
    <script type="text/javascript">
        function printTagSingle(banid, classcode, count) {
            var place = $("#place_" + count).val();
            printTag(banid, place, classcode);
        }
        function printTagOnCreate() {
            var banid = $("input[name='banid']").val();
            var place = $("input[name='place']").val();
            var places = place.split("/");
            printTag(banid, places[1], places[0]);
        }
        /**
         *  打印预览
         */
        //声明为全局变量
        var LODOP;
        function printTag(banid, place, classcode) {
            LODOP = getLodop(document.getElementById('LODOP'), document.getElementById('LODOP_EM'));
            LODOP.PRINT_INIT("打印");
            LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A4");
            var bar = "<div style='background-color:#ffffff;font-size: 18px;text-align: center;'>" +
                    "<div style='height:25px;'>" + classcode + "</div>" +
                    "<div style='height:25px;'>" + place + "</div>" +
                    "<div style='height:16px;font-size: 13px;'>" + banid + "</div>" +
                    "</div>";
            /*// 打印条形码
             LODOP.ADD_PRINT_BARCODE(25, 34, 159, 70, "code39", banid);*/
            // 打印 索书号和分类
            LODOP.ADD_PRINT_HTM(25, 34, 159, 70, bar);
            LODOP.PRINT_DESIGN();
            LODOP.SHOW_CHART();
        }
    </script>

    </body>
</html>